package com.guigu.controller;

import com.guigu.dto.MemberDTO;
import com.guigu.dto.UpdateMemberRequest;
import com.guigu.entity.*;
import com.guigu.service.MemberService;
import com.guigu.vo.InformationVo;
import com.guigu.vo.MemberVo1;
import com.guigu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private MemberService memberService;
     @GetMapping("/findAll")
         public Result<List<MemberVo1>> findAll() {
             List<MemberVo1> MemberList = this.memberService.findAllUserList();
             return new Result<>("200", "true", "成功查询用户列表", MemberList);
         }
    @PostMapping("/addmember")
    public Result add(@RequestBody MemberDTO dto){
        System.out.printf("dto:"+dto.toString());
        this.memberService.add(dto);
        return new Result<>("200", "true", "成功添加用户", null);
    }
    @PostMapping("/Delmember")
    public Result Del(@RequestBody  MemberDTO dto){
         this.memberService.Del(dto.getId());
        return new Result<>("200", "true", "成功删除用户", null);
    }
    @PostMapping("/findOne")
    public Result<MemberVo1> findOne(@RequestBody  MemberDTO dto){
        return new Result<>("200", "true", "成功查询",   this.memberService.findOne(dto.getId()));
    }
    @PostMapping("/findOne1")
    public Result<InformationVo> findOne1(@RequestBody  MemberDTO dto){
        return new Result<>("200", "true", "成功查询",   this.memberService.findOne1(dto.getId()));
    }
    @PostMapping("/findOne2")
    public Result<t_History> findOne2(@RequestBody  MemberDTO dto){
        return new Result<>("200", "true", "成功查询",   this.memberService.findOne2(dto.getId()));
    }
    @PostMapping("/updatemember")
    public Result updatemember(@RequestBody UpdateMemberRequest request) {
         //输出request
        System.out.println(request.toString());
        this.memberService.updatemember(request);
        return new Result<>("200", "true", "成功更新会员信息", null);
    }
    @GetMapping("/user")
    public Result<List<t_account>> user() {
         return  new Result<>("200", "true", "成功更新会员信息", this.memberService.user());
    }
    @PostMapping("/statistics")
    public Result<List<MemberVo1>> statistics(@RequestBody t_statistics dto) {
         System.out.println("1111");
         System.out.println(dto);
        List<MemberVo1> MemberList = this.memberService.statistics(dto);
        return new Result<>("200", "true", "成功查询用户列表", MemberList);
    }
}
